<?php

namespace App\Service\Index;

use App\Model\Banner;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 首页轮播图
 */
class BannerService extends BaseService
{
    public function handle()
    {
        $ret = ['list' => []];
        // if ($this->appId != 1) return $ret;
        $userId = $this->getUserId();
        $platform = $this->request->input('platform', 1);
        $channel = $this->request->input('channel', '');
        $profile = UserProfile::getProfile($userId);
        $data = Banner::getList($platform, $profile->gender, $channel);
        array_walk($data, function ($item) use (&$ret, $profile) {
            $ret['list'][] = Banner::packBanner($item, $profile);
        });
        return $ret;
    }
}
